import asyncio
import aiohttp
import asyncio

async def say_hello():
    await asyncio.sleep(1)  # 模拟异步等待 1 秒
    print("Hello, asyncio!")  # 输出信息

async def main():
    # 创建三个任务并运行
    tasks = [say_hello() for _ in range(3)]
    await asyncio.gather(*tasks)  # 并发执行多个任务

asyncio.run(main())  # 启动事件循环并运行 `main`   任务是并发运行的，所以大约只需 1 秒。

import aiohttp
import asyncio
import time

async def fetch_url(url):
    async with aiohttp.ClientSession() as session:
        async with session.get(url) as response:
            return await response.text()

async def main():
    tasks = [fetch_url("https://example.com") for _ in range(3)]  # 创建 3 个请求任务
    await asyncio.gather(*tasks)  # 并发运行这些任务

start = time.time()
asyncio.run(main())
print(f"Total time: {time.time() - start:.2f} seconds")
